package com.controller;

import com.model.MyLog;
import com.service.MyLogService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "我的用户")
@RestController
@RequestMapping("/myLog")
public class MyLogController {

    @Autowired
    private MyLogService myLogService;

    @CrossOrigin
    @RequestMapping(value = "/addLog", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int addUser(@RequestBody MyLog myLog){
        System.out.println("进入用户添加方法");
        return myLogService.addMyLog(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateMyLog", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int updateUser(@RequestBody MyLog myLog){
        System.out.println("进入用户修改方法，修改的主键为"+ myLog.getId());
        return myLogService.updateMyLog(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/deleteMyLog", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public int deleteMyUser(int id){
        System.out.println("进入删除用户信息，主键为："+ id);
        return myLogService.deleteMyLog(id);
    }

    @CrossOrigin
    @RequestMapping(value = "/getLog", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public MyLog getLog(int id){
        System.out.println("进入根据主键查找用户信息，主键为："+ id);
        return myLogService.getLog(id);
    }

    @CrossOrigin
    @RequestMapping(value = "/getAll", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<MyLog> getAll(@RequestBody MyLog myLog){
        System.out.println("进入用户查询方法");
        System.out.println(myLog.getLoginTi() + "=====" + myLog.getIp());
        List<MyLog> myLogList=myLogService.getAllMyLogs(myLog);
        System.out.println(myLogList.size());
        return myLogService.getAllMyLogs(myLog);
    }

}

